package com.hok.bouncy;

import lombok.extern.slf4j.Slf4j;
import org.bouncycastle.crypto.params.AsymmetricKeyParameter;
import org.bouncycastle.crypto.util.PrivateKeyFactory;

import java.io.IOException;
import java.security.*;

@Slf4j
public class TestMain {

    public static void main(String[] args) {
        KeyPairGenerator generator = null;
        try {
            generator = KeyPairGenerator.getInstance("RSA");
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        }
        generator.initialize(2048, new SecureRandom());
        KeyPair keyPair = generator.generateKeyPair();
        // 公钥
        PrivateKey privateKey = keyPair.getPrivate();
        // 私钥
        PublicKey publicKey = keyPair.getPublic();
        try {
            AsymmetricKeyParameter keyParam = PrivateKeyFactory.createKey(privateKey.getEncoded());
            System.out.println(keyParam);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

}
